package com.example.administrator.printoutindemo;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class UserInfo implements Serializable {

	private int _user_id;
	private String _user_name;
	private String _roles_id;
	private String _user_login;


	// 将JSON对象转化为list
	public List<UserInfo> getListFromJSON(String JsonStr) {
		List<UserInfo> clist = new ArrayList<UserInfo>();

		try {

			JSONArray jay = new JSONArray(JsonStr);// 将字符串转化为JSON数组

			for (int i = 0; i < jay.length(); i++) {
				JSONObject temp = (JSONObject) jay.get(i);

				UserInfo n = new UserInfo();

				n.set_roles_id(temp.getString("roles_id"));
				n.set_user_login(temp.getString("user_login"));
				n.set_user_name(temp.getString("user_name"));
				n.set_user_id(Integer.parseInt(temp.getString("user_id")));

				clist.add(n);

			}

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

		return clist;

	}

	public String get_user_name() {
		return _user_name;
	}

	public void set_user_name(String _user_name) {
		this._user_name = _user_name;
	}

	public String get_roles_id() {
		return _roles_id;
	}

	public void set_roles_id(String _roles_id) {
		this._roles_id = _roles_id;
	}

	public String get_user_login() {
		return _user_login;
	}

	public void set_user_login(String _user_login) {
		this._user_login = _user_login;
	}
	public int get_user_id() {
		return _user_id;
	}

	public void set_user_id(int _user_id) {
		this._user_id = _user_id;
	}

}